package com.zd.dao;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
@TableName("sys_data_displacement")
public class ReceiverData {


    private static Map<String, Integer> deviceInfo = new HashMap<>();
    static {
        deviceInfo.put("0", 0);
    }


    @TableField("sn")
    private String sn;

    @TableField("dy")
    private Float dy;

    @TableField("dx")
    private Float dx;


    @TableField("dz")
    private Float dz;

    @TableField("x")
    private Float x;


    @TableField("y")
    private Float y;

    @TableField("h")
    private Float h;


    @TableField("datetime")
    private Date datetime;


    public byte[] toLocationByteArray(int address) {
        ByteBuffer buffer = ByteBuffer.allocate(29); // 1 + 4 * 6 = 29 bytes
        buffer.order(ByteOrder.LITTLE_ENDIAN); // Assuming little-endian byte order

        // Write address as uint8_t
        buffer.put((byte) (address & 0xFF));

        // Write float values
        buffer.putFloat(x);
        buffer.putFloat(y);
        buffer.putFloat(h); // Assuming 'h' is 'z'
        buffer.putFloat(dx);
        buffer.putFloat(dy);
        buffer.putFloat(dz);

        return buffer.array();
    }

}
